package jp.co.sharp.android.parents.kidsguard.common;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;

import jp.co.sharp.android.parents.kidsguard.R;

public class ProcessPointDlg extends Dialog {

    private OnOperateSetListener mOnOperateSetListener;
    private CheckBox mCbViewDlg;
    private String mMessage;

    public ProcessPointDlg(@NonNull Context context, String pMessage) {
        super(context);
        this.mMessage = pMessage;
    }

    public ProcessPointDlg(@NonNull Context context, int themeResId, String pMessage) {
        super(context, themeResId);
        this.mMessage = pMessage;
    }

    protected ProcessPointDlg(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener, String pMessage) {
        super(context, cancelable, cancelListener);
        this.mMessage = pMessage;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dlg_process_point);

        initDlg();
    }

    private void initDlg() {
        TextView dlgMessage = (TextView)findViewById(R.id.dlgMessage);
        dlgMessage.setText(mMessage);

        mCbViewDlg = (CheckBox)findViewById(R.id.cbViewDlg);

        Button cancelBtn = (Button)findViewById(R.id.cancelBtn);
        cancelBtn.setOnClickListener(new ListenerCancel());
    }

    /**
     *
     */
    public interface OnOperateSetListener {
        void onOperateSet(boolean cbViewDlg);
    }

    /*
     * 对外公开方法让Activity实现
     */
    public void setOnOperateSetListener(OnOperateSetListener callBack) {
        mOnOperateSetListener = callBack;
    }

    class ListenerCancel implements View.OnClickListener {
        @Override
        public void onClick(View view) {
            if (mOnOperateSetListener != null) {
                mOnOperateSetListener.onOperateSet(mCbViewDlg.isChecked());
            }
        }
    }

}
